﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Nop.Core.Log.Model;

namespace Nop.Core.Log.Service
{
    public class LogImpl : ILog
    {
        private readonly ITagbleStorage _storage;

        public LogImpl(ITagbleStorage storage)
        {
            _storage = storage;
        }

        /// <summary>
        /// write info log infomation
        /// </summary>
        /// <param name="message">log</param>
        public void Info(string message)
        {
            if (string.IsNullOrEmpty(message)) return;

            _storage.Insert(message, Assembly.GetCallingAssembly().GetName().Name, Level.Info, "info");
        }

        /// <summary>
        /// write debug log infomation
        /// </summary>
        /// <param name="message">log</param>
        public void Debug(string message)
        {
            if (string.IsNullOrEmpty(message)) return;

            _storage.Insert(message, Assembly.GetCallingAssembly().GetName().Name, Level.Debug, "debug");
        }

        /// <summary>
        /// write error log infomation
        /// </summary>
        /// <param name="message">log</param>
        public void Error(string message)
        {
            if (string.IsNullOrEmpty(message)) return;

            _storage.Insert(message, Assembly.GetCallingAssembly().GetName().Name, Level.Error, "error");
        }

        /// <summary>
        /// write exception log infomation
        /// </summary>
        /// <param name="exception">exception</param>
        public void Exception(Exception exception)
        {
            if (exception == null) return;

            _storage.Insert(exception.ToString(), Assembly.GetCallingAssembly().GetName().Name, Level.Exception, "exception");
        }

        /// <summary>
        /// user-defined write log event
        /// </summary>
        public event EventHandler<EventArgs<Exception>> ProcessException
        {
            add {}
            remove {}
        }

    }
}
